//
// Created by lz on 3/1/21.
//

#ifndef _EPOLLPOLLER_H_
#define _EPOLLPOLLER_H_

#include "net/Poller.h"
#include <vector>


struct epoll_event;

namespace lzweb
{
	namespace net
	{
		class EpollPoller : public Poller
		{
		 public:
			EpollPoller(EventLoop* loop);
			~EpollPoller() override;

			TimeStamp poll(int timeoutMs, ChannelList* activeChannel);

			void updateChannel(Channel* channel) override;
			void removeChannel(Channel* channel) override;

		 private:

			static const int kInitEventListSize = 16;
			static const char* operationToString(int op);

			void fillActiveChannels(int numEvents,
									ChannelList* activeChannels) const;

			void update(int operation, Channel* channel);

			using EventList = std::vector<struct epoll_event>;

			int epollfd_;  // epoll_create的返回值
			EventList  events_;  // 存储epoll返回的事件。 epollpoller通过events.data.ptr ->channel*来存储对应的文件描述符

		};
	}// namespace net
}// namespace lzweb



#endif //_EPOLLPOLLER_H_
